package com.novax.ex.activity.provider.service;

import com.novax.ex.activity.infrastructure.entity.IeoCurrencyConfig;
import com.novax.ex.common.base.BaseMapper;
import com.novax.ex.common.base.BaseService;
import com.novax.ex.common.constant.Currency;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

import com.novax.ex.activity.infrastructure.mapper.IeoCurrencyConfigMapper;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Description 申购币种配置service
 * @Author Cody
 * @Date 2022/12/02/11:51
 */
@Service
public class IeoCurrencyConfigService extends BaseService {

    @Resource
    private IeoCurrencyConfigMapper ieoCurrencyConfigMapper;

    @Override
    protected BaseMapper getBaseMapper() {
        return ieoCurrencyConfigMapper;
    }


    /**
     * 黄涛
     * 通过项目id查询项目的币种和该币种对应的权重问题
     *
     * @param ieoId 项目ID
     * @return 币种和权重信息
     */
    public List<IeoCurrencyConfig> selectListByIeoId(Long ieoId) {
        return ieoCurrencyConfigMapper.selectByIeoId(ieoId);
    }

    /**
     * 黄涛
     * 选择通过ieo id和货币
     *
     * @param ieoId    活动id
     * @param currency 币种名称
     * @return {@link IeoCurrencyConfig}
     */
    public IeoCurrencyConfig findByIeoIdAndCurrency(Long ieoId, String currency) {
        return ieoCurrencyConfigMapper.selectByIeoIdAndCurrency(ieoId, currency);
    }

    /***
     * @Description: 添加IEO活动时默认配置币种为USDT
     * @Author: ChenXi
     * @Date:  2023/4/25 14:50
     * @param ieoId
     * @return: void
     **/
    public void addDefaultCurrency(Long ieoId) {
        IeoCurrencyConfig ieoCurrencyConfig = new IeoCurrencyConfig();
        ieoCurrencyConfig.setIeoId(ieoId);
        ieoCurrencyConfig.setCurrency(Currency.USDT);
        ieoCurrencyConfig.setCreateTime(new Date());
        ieoCurrencyConfig.setAmount(BigDecimal.ONE);
        ieoCurrencyConfig.setWeight(BigDecimal.ONE);
        // 默认计价币种转USDT汇率为1 : 1
        ieoCurrencyConfig.setUsdtRate(BigDecimal.ONE);
        // 计价币种默认为USDT
        ieoCurrencyConfig.setIsPricingCurrency(1);
        addSelective(ieoCurrencyConfig);
    }

    /**
     * @Description: 查询计价币种
     * @Author: ChenXi
     * @Date:  2023/4/25 14:53
     * @param ieoId
     * @return: void
     **/
    public IeoCurrencyConfig findByIsPricingCurrency(Long ieoId) {
        return ieoCurrencyConfigMapper.findByIsPricingCurrency(ieoId);
    }

}
